package org.dhbw.jee.web.security;

import java.math.BigInteger;
import java.security.MessageDigest;

public class Hash {

	public static String toMD5(String s) {
		byte[] bytesOfMessage = null;
		MessageDigest md = null;

		try {
			bytesOfMessage = s.getBytes();
			md = MessageDigest.getInstance("MD5");
		} catch (Exception e) {
			// type of Exception does not matter here
			e.printStackTrace();
			return null;
		}
		
		md.update(bytesOfMessage);

		return new BigInteger(1, md.digest()).toString(16);
	}
	
	public static void main(String[] args) {
		System.out.println(toMD5("123"));
	}
}
